package com.haoan.index.service.impl;


import java.util.List;
import javax.annotation.Resource;

import com.haoan.index.mapper.PersonnelMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.CulturalRelicMapper;
import com.haoan.index.domain.CulturalRelic;
import com.haoan.index.service.CulturalRelicService;

/**
 * 文物Service业务层处理
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Service
public class CulturalRelicServiceImpl extends ServiceImpl<CulturalRelicMapper,CulturalRelic> implements CulturalRelicService
{
    /**
     * 查询文物
     *
     * @param id 文物主键
     * @return 文物
     */
    @Override
    public CulturalRelic selectCulturalRelicById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询文物列表
     *
     * @param culturalRelic 文物
     * @return 文物
     */
    @Override
    public List<CulturalRelic> selectCulturalRelicList(CulturalRelic culturalRelic)
    {
        LambdaQueryWrapper<CulturalRelic> queryWrapper = new LambdaQueryWrapper<>();
        //todo 添加查询条件
        queryWrapper.eq(culturalRelic.getId() != null, CulturalRelic::getId, culturalRelic.getId());
        queryWrapper.like(culturalRelic.getName() != null, CulturalRelic::getName, culturalRelic.getName());
        queryWrapper.eq(culturalRelic.getPicture() != null, CulturalRelic::getPicture, culturalRelic.getPicture());
        queryWrapper.like(culturalRelic.getEra() != null, CulturalRelic::getEra, culturalRelic.getEra());
        queryWrapper.like(culturalRelic.getTexture() != null, CulturalRelic::getTexture, culturalRelic.getTexture());
        queryWrapper.like(culturalRelic.getRegion() != null, CulturalRelic::getRegion, culturalRelic.getRegion());
        queryWrapper.like(culturalRelic.getAddress() != null, CulturalRelic::getAddress, culturalRelic.getAddress());
        queryWrapper.eq(culturalRelic.getPrice() != null, CulturalRelic::getPrice, culturalRelic.getPrice());
        queryWrapper.eq(culturalRelic.getDetail() != null, CulturalRelic::getDetail, culturalRelic.getDetail());
        queryWrapper.eq(culturalRelic.getLikes() != null, CulturalRelic::getLikes, culturalRelic.getLikes());
        queryWrapper.eq(culturalRelic.getCreateTime() != null, CulturalRelic::getCreateTime, culturalRelic.getCreateTime());
        queryWrapper.eq(culturalRelic.getCreateBy() != null, CulturalRelic::getCreateBy, culturalRelic.getCreateBy());
        queryWrapper.eq(culturalRelic.getUpdateTime() != null, CulturalRelic::getUpdateTime, culturalRelic.getUpdateTime());
        queryWrapper.eq(culturalRelic.getUpdateBy() != null, CulturalRelic::getUpdateBy, culturalRelic.getUpdateBy());
        queryWrapper.eq(CulturalRelic::getValiFlag,ValiFlag.VALID );
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 新增文物
     *
     * @param culturalRelic 文物
     * @return 结果
     */
    @Transactional
    @Override
    public int insertCulturalRelic(CulturalRelic culturalRelic)
    {
        return baseMapper.insert(culturalRelic);
    }

    /**
     * 修改文物
     *
     * @param culturalRelic 文物
     * @return 结果
     */
    @Transactional
    @Override
    public int updateCulturalRelic(CulturalRelic culturalRelic)
    {
        return baseMapper.updateById(culturalRelic);
    }

    /**
     * 批量删除文物
     *
     * @param ids 需要删除的文物主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteCulturalRelicByIds(Long [] ids)
    {
        CulturalRelic culturalRelic = new CulturalRelic();
        culturalRelic.setValiFlag(ValiFlag.INVALID);
        LambdaQueryWrapper<CulturalRelic> updQw = new LambdaQueryWrapper<>();
        updQw.in(CulturalRelic::getId, ids);
        return baseMapper.update(culturalRelic, updQw);
    }

    /**
     * 删除文物信息
     *
     * @param id 文物主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        CulturalRelic culturalRelic = getById(id);
        culturalRelic.setValiFlag(ValiFlag.INVALID);
        return baseMapper.updateById(culturalRelic);
    }
}
